/* eslint-disable indent */
import { connect } from 'dva';
import React, { Component } from 'react';
import { Modal, Form, Input,Radio,Switch } from 'antd';

const FormItem = Form.Item;
const ${className}EditForm = ({dispatch,record,form,editVisible}) =>{
    const { getFieldDecorator } = form;

    /**
     * 显示对话框
     */
    const handleModelShow = () => {
        dispatch({type: '${classObjectName}/handleEditModelState', payload:{editVisible: true}});
    };
    /**
     * 隐藏对话框
     */
    const handleModelHide = () =>{
        dispatch({type: '${classObjectName}/handleEditModelState',payload:{editVisible:false}});
    };
    /**
     * 表单提交
     */
    const handleFormSubmit = () =>{
        form.validateFields((err, values) => {
            if (!err) {
                dispatch({type: '${classObjectName}/edit',payload:{values}});
                handleModelHide();
                handleFormClear();
            }
        });
    };
    /**
     * 表单重置
     */
    const handleFormClear = () =>{
        form.resetFields();
    };
    const formItemLayout = {
        labelCol: { xs: {span: 10}, sm: {span: 5} },
        wrapperCol: { xs: {span: 24}, sm: {span: 14} }
    };

    const body = (
        <span>
            <Modal visible={editVisible} title="编辑表单" okText="提交" afterClose={handleFormClear} onCancel={handleModelHide} onOk={handleFormSubmit}>
              <Form layout="vertical">
              <#list fields as field>
                  <#if field.fieldName != keyName>
                      <FormItem {...formItemLayout} label="${field.remarks}" hasFeedback>
                  {getFieldDecorator('${field.fieldName}', {initialValue:record.${field.fieldName},
                    rules: [{ required: true, message: '请输入${field.remarks}！'}],
                  })(<Input />)}
                </FormItem>
                  </#if>
              </#list>
              </Form>
            </Modal>
        </span>
    );

    return body ;
};

function mapStateToProps(state) {
    const {editVisible,record} = state.${classObjectName};
    return { editVisible, record };
}

export default Form.create({})(connect(mapStateToProps)(${className}EditForm));
